#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <stdlib.h>
#include <fcntl.h>
#include <sys/wait.h>
#include <signal.h>

void hanlderSignal(int sig)
{
    /* */
    printf("执行自定义动作\n");
}

#define FIFONAME "./testFifo"


void my_exit(int sig)
{
    if(sig == SIGALRM)
    {
        printf("hello\n");
    }
    else
        printf("子进程接受信号\n");
}

int main()
{


#if 0
    int a = 100;
    int b = 0;
    int c = a / b;
    printf("c = %d\n",c);
#endif

#if 0
    char *ptr = NULL;
    printf("%c\n",*ptr);
#endif

#if 0
    /* 创建管道 */
    int pipeFd[2] = {0};
    pipe(pipeFd);

    /* 关闭管道读端 */
    close(pipeFd[0]);

    /* 向写端写数据 */
    write(pipeFd[1],"123",strlen("123"));

#endif

#if 0
pid_t pid = fork();
    if(pid < 0)
    {

    }
    else if(pid == 0)
    { 
        signal(SIGINT,my_exit);
        while(1)
        {
            pause();
        }
            
    }
    else
    {
        sleep(1);
        while(1)
        {
            kill(pid,SIGINT);
            sleep(2);
        }
        
    }
#endif

#if 1
    
    signal(SIGALRM,my_exit);
    int cnt = 100;
    while(cnt--)
    {
        alarm(5);
        pause();
    }

#endif


    return 0;
}